package Abnormal;

/**
 * 老师有年龄，学校，姓名的属性，有上课和自我介绍的方法，如果年龄少于22岁，抛出异常。
 */
public class Teacher {
    private int age;
    private String school;
    private String name;
public void self(){
    System.out.println("这位老师姓名是"+name+"年龄是"+age+"在"+school+"学校任职");
    try {
        if (age<22){
            throw new Exception("年龄输入错误");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
public void teach() {
    System.out.println("老师在教学生上课");
}
    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Teacher(int age, String school, String name) {
        this.age = age;
        this.school = school;
        this.name = name;
    }
}
class Test{
    public static void main(String[] args) {
        Teacher a=new Teacher(20,"毛坦厂","老刘");
        a.self();
        a.teach();
    }
}